package com.huoniu.user.controller;

import com.huoniu.user.utils.COSStorage;
import com.huoniu.user.utils.StringUtil;
import com.qcloud.cos.model.ObjectMetadata;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.operator.InputAEADDecryptor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.annotation.MultipartConfig;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * @类 名： UploadController <br/>
 * @描 述： <br/>
 * @日 期： 2020/10/5 14:10<br/>
 * @作 者： 侯建军<br/>
 * @版 本： 1.0.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(value = "/upload")
@Slf4j
@CrossOrigin
public class UploadController {

    @PostMapping("upload")
    public String upload(MultipartFile file) throws IOException {
        String filename=file.getOriginalFilename();
        InputStream inputStream=file.getInputStream();
        COSStorage cosStorage = new COSStorage();
        String path = cosStorage.upload(inputStream, StringUtil.getFileExt(filename));
        log.info(path);
        return path;
    }
}
